<?php
namespace App\Service\Admin;

use App\Service\BaseService as Service;

class BaseService extends Service
{
    //基础服务

    //返回参数
    public function toback($code = 0, $msg = '', $data = [], $total = 0)
    {
        $msg = $msg ? $msg : 'success';
        return array('code' => $code, 'msg' => $msg, 'data' => $data, 'total' => $total);
    }

    //获取配置
    public function getConfig($key = '')
    {
        $db = $this->dbwbConn($this->dbQdConfig);
        $res = $db->get();
        if (!$key) {
            $arys = [];
            foreach ($res as $v) {
                $v = (array) $v;
                $arys[$v['key']] = $v['value'];
            }
            return $this->toback(0, '', $arys);
        }
        $res = (array) $db->where('key', $key)->first();
        if (empty($res)) {
            return $this->toback(-2, '没有参数');
        }
        return $this->toback(0, '', $res['value']);
    }

    //通过token获取管理员aid
    public function aidByToken($token)
    {
        return $this->dbConn($this->dbAdLogin)
            ->where('token', $token)
            ->orderBy('id', 'desc')
            ->value('adminid');
    }
}